Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chai-style

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-style

CSS Style assertions for elements, using Chai.js

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
504
increased by47.37%
Maintainers
2
Weekly downloads
 
Created
Source

Build Status

chai-style

CSS Style assertions for elements, using Chai.js. All assertions is builtin using window.getComputedStyle method.

Install

npm install --save-dev chai-style
// in your spec, set the plugin in chai
const {expect} = require('chai')
  .use(require('chai-style'))

Style as chainable assertion

Use method .style to inspect style of a element, e.g.

const element = document.querySelector('h2')
expect(element).to.have.style('color', 'red')

Properties can be defined in camel case or separated by hifen, like in css

expect(element).to.have.style('backgroundColor')
// or
expect(element).to.have.style('background-color')

Values

To assert a value just pass a second argument to method style, like below

// assert if element has property display with value black
expect(element).to.have.style('display', 'block')

Colors

Some browsers can generate a differente value to color, like 'red' or 'rgb(255, 0, 0)'. Whatever, this assertion supports named colors, rgb, rgba, hexadecimal, and hsl

element.style.color = '#f00'
expect(element).to.have.style('color', 'red') // asserts colors indiferrent of value used

Units

To assert unit values, use like css

element.style.height = '50vh'
expect(element).to.have.style('height', '50vh')
// too works if you assert with respective value in pixels
expect(element).to.have.style('height', '323px') // 323 is the half of viewport in this case, equals to 50vh

Actually, the css units supported is

  • px (pixels)
  • em (relative to element fontStyle, or inherit)
  • rem (relative to root fontStyle, the html tag)
  • vh (viewport height)
  • vw (viewport width)

Other units will come soon. Pull requests be welcome!

Keywords

FAQs

Package last updated on 16 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc